package com.example.domain;

import java.io.Serializable;
import java.util.ArrayList;

public class Menu implements Serializable {
	private int id;
	private String title;
	private ArrayList<MenuItem> menuItems;
	
	public Menu(int id, String title) {
		this.id = id;
		this.title = title;
		menuItems = new ArrayList<MenuItem>();
	}
	
	public Menu(String title, ArrayList<MenuItem> items) {
		this.title = title;
		this.menuItems = items;
	}

	public boolean addMenuItem(MenuItem newMenuItem) {
		MenuItem matchingItem = findMenuItem(newMenuItem);
		// Check if the item already exists
		if (matchingItem == null) {
			menuItems.add(newMenuItem);
			return true;
		}
		return false;
	}

	/**
	 * @param itemToFind
	 * @return an instance of MenuItem. Instance is null if no matching item is found.
	 */
	public MenuItem findMenuItem(MenuItem itemToFind) {
		MenuItem matchingItem = null;
		for (MenuItem mi : menuItems) {
			if (mi.getTitle().equals(itemToFind.getTitle())	&& mi.getItemType().equals(mi.getItemType())) {
				matchingItem = mi;
				break;
			}
		}
		return matchingItem;
	}
	
	public int getId() { return id; }
	public String getTitle() { return title; }
	public ArrayList<MenuItem> getMenuItems() { return menuItems; }
}
